package com.lsj.text;

import com.alibaba.druid.pool.DruidDataSource;

import com.lsj.util.SpringConfig;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.sql.SQLException;

public class AnnotationTest {
    @Test
    public void r(){
        AnnotationConfigApplicationContext applicationContext=new AnnotationConfigApplicationContext(SpringConfig.class);
        Object r1 = applicationContext.getBean("r");
        Object r2 = applicationContext.getBean("r");
        System.out.println(r1);
        System.out.println(r1==r2);
        System.out.println(r1.hashCode()+"|"+r2.hashCode());
        applicationContext.close();
    }

    @Test
    public void u(){
        AnnotationConfigApplicationContext applicationContext=new AnnotationConfigApplicationContext(SpringConfig.class);
        Object u1 = applicationContext.getBean("u");
        Object u2 = applicationContext.getBean("u");
        System.out.println(u1);
        System.out.println(u1==u2);
        System.out.println(u1.hashCode()+"|"+u2.hashCode());
        applicationContext.close();
    }
    @Test
    public void druid() throws SQLException {
        AnnotationConfigApplicationContext applicationContext=new AnnotationConfigApplicationContext(SpringConfig.class);
        DruidDataSource druid= (DruidDataSource) applicationContext.getBean("druid");
        System.out.println(druid.getConnection());
        applicationContext.close();
    }
}
